package com.cn.web.bean;

import cn.com.allunion.common.page.QueryResult;
import cn.com.allunion.sms.pojo.Smsrecord;
import com.alibaba.fastjson.annotation.JSONField;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 短信记录结果集
 * Created by YangJie on 2016/4/22.
 */
public class SmsrecordResult {
    /**
     * 短信通道名称
     */
    private String operatorName ;

    /**
     * 对应业务代码
     */
    private String businessCode ;

    /**
     * 对应业务名称
     */
    private String businessName ;

    /**
     * 接收短信手机号码
     */
    @JSONField(name = "phoneNumber")
    private String sendNumber;

    /**
     * 短信内容
     */
    @JSONField(name = "content")
    private String sendContent;

    /**
     * 发送状态
     */
    @JSONField(name = "status")
    private String sendState;
    /**
     * 发送时间
     */
    @JSONField(name = "datetime", format = "yyyy-MM-dd HH:mm:ss")
    private Date createDate;

    /**
     * 来源IP
     */
    private String fromIP;

    public static QueryResult<SmsrecordResult> convert(QueryResult<Smsrecord> queryResult) {
        if (null == queryResult) {
            return null ;
        }
        return new QueryResult<SmsrecordResult>(convert(queryResult.getResultList()), queryResult.getTotalRecord()) ;
    }

    /**
     * 将Smsrecord集合转换为SmsrecordResult集合
     * @param smsrecords 待转换的集合对象
     * @return 转换后的结果
     */
    public static List<SmsrecordResult> convert(List<Smsrecord> smsrecords) {
        if (null == smsrecords) {
            return null ;
        }
        List<SmsrecordResult> smsrecordResults = new ArrayList<>(smsrecords.size()) ;
        for (Smsrecord so : smsrecords) {
            smsrecordResults.add(convert(so));
        }

        return smsrecordResults ;
    }

    /**
     * 将Smsrecord对象转换为SmsrecordResult
     * @param smsrecord 要转换的对象
     * @return 转换后的对象
     */
    public static SmsrecordResult convert(Smsrecord smsrecord) {
        if (null == smsrecord) {
            return null;
        }
        SmsrecordResult result = new SmsrecordResult() ;
        BeanUtils.copyProperties(smsrecord, result);
        result.setOperatorName(smsrecord.getSmsOperator().getSmsOperatorName());
        result.setBusinessName(smsrecord.getSmsBusinessRecord().getSmsBusinessName());
        result.setBusinessCode(smsrecord.getSmsBusinessRecord().getBusinessCode());

        return result ;
    }


    public String getOperatorName() {
        return operatorName;
    }

    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }

    public String getBusinessCode() {
        return businessCode;
    }

    public void setBusinessCode(String businessCode) {
        this.businessCode = businessCode;
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getSendNumber() {
        return sendNumber;
    }

    public void setSendNumber(String sendNumber) {
        this.sendNumber = sendNumber;
    }

    public String getSendContent() {
        return sendContent;
    }

    public void setSendContent(String sendContent) {
        this.sendContent = sendContent;
    }

    public String getSendState() {
        return sendState;
    }

    public void setSendState(String sendState) {
        this.sendState = sendState;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getFromIP() {
        return fromIP;
    }

    public void setFromIP(String fromIP) {
        this.fromIP = fromIP;
    }
}
